﻿'© 2004 - 2008 ActiveModules, Inc. All Rights Reserved
Namespace DotNetNuke.Modules.ActiveForums
    Partial Public Class af_subscribe
        Inherits ForumBase
#Region "Public Members"
        Public mode As Integer = 1 '0 = Forum 1 = Topic
        Public IsSubscribed As Boolean = False
#End Region
#Region "Event Handlers"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim SubscribeText As String
            If mode = 0 Then
                SubscribeText = GetSharedResource("[RESX:ForumSubscribe:" & IsSubscribed.ToString.ToUpper & "]")
            Else
                SubscribeText = GetSharedResource("[RESX:TopicSubscribe:" & IsSubscribed.ToString.ToUpper & "]")
            End If
            chkSubscribe.Text = SubscribeText
            chkSubscribe.Checked = IsSubscribed
            If UseAjax Then
                chkSubscribe.Attributes.Add("onclick", "af_toggleSub();")
                AddToggleScript()
            Else
                chkSubscribe.AutoPostBack = True
            End If
        End Sub
        Private Sub cbSubscribe_Callback(ByVal sender As Object, ByVal e As Modules.ActiveForums.Controls.CallBackEventArgs) Handles cbSubscribe.Callback
            ToggleSubscribe()
            chkSubscribe.RenderControl(e.Output)
        End Sub
        Private Sub chkSubscribe_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSubscribe.CheckedChanged
            ToggleSubscribe()
        End Sub
#End Region
#Region "Private Methods"
        Private Sub AddToggleScript()
            Dim sb As New Text.StringBuilder
            sb.Append("function af_toggleSub(){" & cbSubscribe.ClientID & ".Callback();};")
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "afsubscribe", sb.ToString, True)
        End Sub
        Private Sub ToggleSubscribe()
            Dim iStatus As Integer = 0
            Dim sc As New SubscriptionController
            iStatus = sc.Subscription_Update(PortalId, ModuleId, ForumId, TopicId, 1, Me.UserId, ForumUser.UserRoles)
            If iStatus = 1 Then
                IsSubscribed = True
            Else
                IsSubscribed = False
            End If
            chkSubscribe.Checked = IsSubscribed
            If mode = 0 Then
                chkSubscribe.Text = GetSharedResource("[RESX:ForumSubscribe:" & IsSubscribed.ToString.ToUpper & "]")
            Else
                chkSubscribe.Text = GetSharedResource("[RESX:TopicSubscribe:" & IsSubscribed.ToString.ToUpper & "]")
            End If


        End Sub
#End Region
    End Class
End Namespace
